##
##  $Header: /pub/cvsroot/mydns/doc/Makefile.am,v 1.33 2002/09/12 08:38:39 bboy Exp $
##

MAN_PAGES		=	mydns.conf.5 mydns.8 mydnscheck.8 mydnsexport.8 mydnsimport.8

EXTRA_DIST		=	$(MAN_PAGES:=.in) $(TEXI) \
						support/texi2html texi2html.init fdl.texi \
						nls/es/mydns.conf.5.in nls/es/mydns.8.in nls/es/mydnscheck.8.in \
							nls/es/mydnsexport.8.in nls/es/mydnsimport.8.in

TARGETDIRS		=	man info html

TEXIVARS			=	variables.texi
SEDFILE 			=	../version.sed

TEXI				=	@PACKAGE_NAME@.texi
INFO				=	$(TEXI:texi=info)
HTML				=	$(TEXI:texi=html)
DEPS				=	$(TEXI) $(TEXIVARS)

RUN				=	$(SHELL) $(top_srcdir)/missing --run


targetdirs:
	for d in $(TARGETDIRS); do if ! test -d $$d; then mkdir $$d; fi; done

## Creates a small .sed script to replace various variables
sedvars:
	if ! `test -f $(SEDFILE)`; then cd .. && make sedfile; fi

## Create a .texi file including the variables
variables.texi:
	@if `test -f $(TEXIVARS)`; then rm -f $(TEXIVARS); fi
	@echo "@set MYDNSCONF @MYDNS_CONF@" >> $(TEXIVARS)
	@echo "@set PKGDATE @PACKAGE_DATE@" >> $(TEXIVARS)
	@echo "@set PKGNAME @PACKAGE_NAME@" >> $(TEXIVARS)
	@echo "@set PKGVERSION @PACKAGE_VERSION@" >> $(TEXIVARS)
	@echo "@set PKGSTRING @PACKAGE_STRING@" >> $(TEXIVARS)
	@echo "@set PKGAUTHOR @PACKAGE_AUTHOR@" >> $(TEXIVARS)
	@echo "@set PKGBUGREPORT @PACKAGE_BUGREPORT@" >> $(TEXIVARS)
	@echo "@set PKGHOMEPAGE @PACKAGE_HOMEPAGE@" >> $(TEXIVARS)
	@echo "@set PKGCOPYRIGHT @PACKAGE_COPYRIGHT@" >> $(TEXIVARS)

vars: targetdirs sedvars variables.texi

info: $(DEPS)
	if $(RUN) makeinfo --version | head -1 | grep \[4-9\]\.\[0-9\] > /dev/null 2>&1; then \
	  $(RUN) makeinfo -o info/$(INFO) $(TEXI); \
	fi
	@if ! test -f info/$(INFO); then \
	  echo; \
	  echo "*** GNU \"info\" documentation not created - you probably need makeinfo."; \
	  echo "*** See http://www.fsf.org/software/texinfo/texinfo.html for details."; \
	  echo; \
	fi

html-doc: $(DEPS)
	$(RUN) perl support/texi2html -init_file=texi2html.init $(TEXI)
	@if ! test -f html/$(HTML); then \
	  echo; echo "*** HTML documentation not created - you probably need perl"; echo; \
	else \
	  if test -f ../extras/graphics/mydns-logo.png; then \
	    cp -f ../extras/graphics/mydns-logo.png html; \
	  fi; \
	fi

html-doc-web: $(DEPS)
	if test -d @WEBROOT@; then \
	  $(RUN) perl support/texi2html -init_file=@WEBROOT@/doc/texi2html.init $(TEXI); \
	fi

html: html-doc

pdf-create:
	if ! test -d pdf; then mkdir pdf; fi
	cp -f $(TEXI) tmp.texi
	pdftex --interaction=nonstopmode tmp.texi
	texindex tmp.??
	pdftex --interaction=nonstopmode tmp.texi
	texindex tmp.??
	pdftex --interaction=nonstopmode tmp.texi
	mv tmp.pdf pdf/mydns.pdf
	rm -f tmp.*

pdf: $(DEPS) pdf-create

manpages: $(MAN_PAGES:=.in)
	for f in $(MAN_PAGES); do \
	  srcdir=.; \
	  if ! test -z "$$LANG"; then \
	    if test -f nls/$$LANG/$$f.in; then \
	      srcdir=nls/$$LANG; \
	    else \
	      lng=`echo $$LANG | $(RUN) sed -e 's/_..//'`; \
	      if test -f nls/$$lng/$$f.in; then \
	        srcdir=nls/$$lng; \
	      fi; \
	    fi; \
	  fi; \
	  $(RUN) sed -f $(SEDFILE) $$srcdir/$$f.in > man/$$f; \
	done

mydns_letter.ps: $(DEPS)
	if ! test -d ps; then mkdir ps; fi
	MAKEINFO='$(RUN) $(MAKEINFO) -I $(srcdir)' $(RUN) texi2dvi --batch --clean $<
	$(RUN) dvips -t letter mydns.dvi -o ps/$@

mydns_a4.ps: $(DEPS)
	if ! test -d ps; then mkdir ps; fi
	MAKEINFO='$(RUN) $(MAKEINFO) -I $(srcdir)' $(RUN) texi2dvi --batch --clean $<
	$(RUN) dvips -t a4 mydns.dvi -o ps/$@

ps: mydns_letter.ps mydns_a4.ps

all: vars manpages info html-doc

clean:
	rm -rf $(TARGETDIRS) pdf ps
	rm -f *~ core* $(TEXIVARS) mydns.dvi

man-install: manpages
	for f in $(MAN_PAGES); do \
	  if test -f man/$$f; then \
	    $(INSTALL) -d $(DESTDIR)$(mandir)/man`echo $$f | sed -e 's/^.*\\.//'`; \
	    $(INSTALL_DATA) man/$$f $(DESTDIR)$(mandir)/man`echo $$f | sed -e 's/^.*\\.//'`/$$f; \
	  fi; \
	done

info-install: info
	if test -f info/$(INFO); then \
	  $(INSTALL) -d $(DESTDIR)$(infodir); \
	  $(INSTALL_DATA) info/$(INFO) $(DESTDIR)$(infodir)/$(INFO); \
	fi

install: all man-install info-install

## Target the author uses to install docs on the homepage:
release: vars manpages html-doc-web pdf ps
	rm -f info/$(INFO)
	rm -f @WEBROOT@/doc/pdf/*.pdf && cp -a pdf/*.pdf @WEBROOT@/doc/pdf
	rm -f @WEBROOT@/doc/ps/*.ps && cp -a ps/*.ps @WEBROOT@/doc/ps
	rm -f @WEBROOT@/doc/man/*.[0-9] && cp -a man/*.[0-9] @WEBROOT@/doc/man

## vi:set ts=3:
